$(function () {
    layui.use('form', function () {
        var form = layui.form;
        // layer.msg('����������', function(){
        //   弹窗关闭后处理
        //   });
        //�����ύ
        form.on('submit(login)', function (data) {
            // alert(888)
            data = data.field;
            //post请求
            let res = request("http://localhost:8080/manager/login", 'post', data)
            //验证码错误
            if (res.code === -1) {
                layer.msg(res.msg,{icon:7,time:2000});
                $("#code").focus().val('');
                changeCode($('#img'))
                //账号密码错误
            } else if (res.code === 1) {
                layer.msg(res.msg,{icon:7,time:2000});
                $("#managerName").focus();
                //登录成功
            } else if (res.code === 0) {
                sessionStorage.setItem("managerName", res.msg)
                sessionStorage.setItem("loginID", res.data.id);
                layer.msg("登录成功",{icon:6,time:2000}, function () {
                    sessionStorage.setItem('Token',res.data)
                    location.replace('/admin/index.html');
                });
            }
            // layer.msg(JSON.stringify(data.field),function(){
            //     location.href='index.html'
            // });
            return false;
        });
    });
})

//点击修改验证码图片
function changeCode(obj) {
    $(obj).attr('src', 'http://localhost:8080/code?aa=' + Math.random());
}